import java.io.*;
import java.util.StringTokenizer;

/**
 * User: Aleksey
 * Date: 17.02.2009
 * Time: 23:18:44
 */
public class check18 {
    private static int getSum(int[] d, int[][] m, int n) {
        int dist = 0;
        for (int i = 1; i < n; i++) {
            dist += (m[d[i-1]][d[i]]);
        }
        dist += m[d[n-1]][d[0]];
        return dist;
    }

    public static void main(String[] args) {
        File inputFile = new File(args[0]);
        File userOutputFile = new File(args[1]);
        //File templateOutputFile = new File(args[2]);

        int result = 0;
        try {
            BufferedReader br1 = new BufferedReader(new FileReader(userOutputFile));
            BufferedReader br2 = new BufferedReader(new FileReader(inputFile));

            int n = Integer.parseInt(br2.readLine().trim());
            int[][] m = new int[n][n];

            for (int i = 0; i < n; i++) {
                StringTokenizer st = new StringTokenizer(br1.readLine());
                for (int j = 0; j < n; j++) {
                    m[i][j] = Integer.parseInt(st.nextToken());
                }
                if (st.hasMoreTokens()) {
                    System.exit(1);
                }
            }
            int ok[] = new int[n*n];
            int sum1 = n*(n*n+1)/2;
            for (int i = 0; i < n; i++) {
                int sum = 0;
                for (int j = 0; j < n; j++) {
                    sum += m[i][j];
                    ok[m[i][j]-1]++;
                }
                if (sum != sum1) {
                    System.exit(1);
                }
            }
            for(int i=0;i<n*n;i++){
                if (!(ok[i]==1)) System.exit(1);
            }
            br1.close();
            br2.close();
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        System.exit(result);
    }
}